var perfectModel
showPerfectModel = function () {
    let token = getToken();
    if (token !== undefined) {
        perfectModel = new bootstrap.Modal(document.getElementById('perfectModal'), {
            //点击背景不关闭
            backdrop: "static",
            //触发键盘esc事件时不关闭
        })
        perfectModel.show()
    } else {
        showLoginModel()
    }
}

collectionAuthor = function (authorId) {
    let token = getToken();
    if (token !== undefined) {
        let value = document.getElementById('collection').innerText;
        console.log(value)
        if (value === '收藏') {
            axios({
                url: '/api/collection',
                method: 'post',
                headers: {'Authorization': token},
                params: {
                    resId: authorId,
                    collectionType: 2
                }
            }).then(function (response) {
                if (response.data.code === 200) {
                    Qmsg.success("收藏成功")
                    //清楚token
                    document.getElementById('collection').innerText = '已收藏'
                } else {
                    if ((response.data.code === 403||response.data.code === 401)){
                        clearToken()
                    }
                    Qmsg.error(response.data.msg)
                }
            }).catch(function (error) {
                console.log(error);
                Qmsg.error("未知错误")
            });
        } else if (value === '已收藏') {
            axios({
                url: '/api/collection',
                method: 'delete',
                headers: {'Authorization': token},
                params: {
                    resId: authorId,
                    collectionType: 2
                }
            }).then(function (response) {
                if (response.data.code === 200) {
                    //清楚token
                    document.getElementById('collection').innerText = '收藏'
                } else {
                    if ((response.data.code === 403||response.data.code === 401)){
                        clearToken()
                    }
                    Qmsg.error(response.data.msg)
                }
            }).catch(function (error) {
                console.log(error);
                Qmsg.error("未知错误")
            });
        }
    } else {
        showLoginModel()
    }
}
